import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = a % b;
        while (c != 0){
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);
    }
    public static void main2(String[] args) {
        //判断指定数字内是否为素数
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int k = 1; k <= n; k++) {


            int i = 2;
            for (; i <= Math.sqrt(k); i++) {
                if (k % i == 0) {
                    System.out.println(k+"不是素数");
                    break;
                }
            }
            if (i > Math.sqrt(k)) {
                System.out.println(k+"是素数");
            }
        }
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0;
        for (int i = 0; i <= n; i++) {
            if (n % 10 == 9){
                count++;
            }
            if (n / 10 == 9){
                count++;
            }

        }
    }
}
